package testinggggg;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author lengogiang
 */
public class SAXVDTD {
    public static void main(String[] args){
        try {
//            SAXParserFactory fac = SAXParserFactory.newInstance();
//            fac.setValidating(true);
//            SAXParser parser = fac.newSAXParser();
            DefaultHandler handler = new MyErrorHandler();
//            parser.parse(new File("test.xml"), handler);


            DocumentBuilderFactory facDom = DocumentBuilderFactory.newInstance();
            facDom.setValidating(true);
            DocumentBuilder parserDom  =  facDom.newDocumentBuilder();
            parserDom.setErrorHandler(handler);
            Document doc = parserDom.parse(new File("test.xml"));
            
            
        } catch (IOException ex) {
            Logger.getLogger(SAXVDTD.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(SAXVDTD.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SAXException ex) {
            Logger.getLogger(SAXVDTD.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
}
